﻿using System;
using System.Collections.Generic;
using System.IO;

namespace YArchitech.LIB
{
	public class FileTools
	{
		public static List<FileInfo> GetAllFileInfo(string pathName)
		{
			DirectoryInfo directoryInfo = new DirectoryInfo(pathName);
			List<FileInfo> list = new List<FileInfo>();
			foreach (FileInfo item in directoryInfo.GetFiles())
			{
				list.Add(item);
			}
			return list;
		}

		public static bool DeleteFileInfo(FileInfo fileInfo)
		{
			bool result = false;
			try
			{
				fileInfo.Delete();
				result = true;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		public static string GetSaveFilePath(string fileName, string extensionName, ref int index)
		{
			string text;
			if (index == 0)
			{
				text = Path.Combine(Product.UserDataLocation, fileName + extensionName);
			}
			else
			{
				text = Path.Combine(Product.UserDataLocation, fileName + index + extensionName);
			}
			if (File.Exists(text))
			{
				index++;
				text = FileTools.GetSaveFilePath(fileName, extensionName, ref index);
			}
			return text;
		}
	}
}
